package com.apartment.own.domain;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.apartment.common.core.domain.BaseEntity;
import com.apartment.own.domain.enums.AccountInstallmentPaymentStatusEnum;
import com.apartment.own.domain.enums.BillAccountTypeEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.apartment.common.annotation.Excel;
import lombok.AllArgsConstructor;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * 账单分期对象 own_account_installment
 * 
 * @author @Dog_E
 * @date 2020-08-28
 */
@Data
@ApiModel("账单分期")
@JsonInclude(JsonInclude.Include.NON_NULL)
@AllArgsConstructor
@NoArgsConstructor
public class OwnAccountInstallment extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 主键id */
    @ApiModelProperty("主键id")
    private String  id;

    @ApiModelProperty("外键账单详情表")
    private String accountDetailsId;

    /** 删除标志（0代表存在 2代表删除） */
    @ApiModelProperty("删除标志（0代表存在 2代表删除）")
    private String delFlag;

    /** 合同id */
    @ApiModelProperty("合同id")
    @Excel(name = "合同id")
    private String contractId;

    /** 账单名 (1期 2期 押金) */
    @ApiModelProperty("账单名 (1期 2期 押金)")
    @Excel(name = "账单名 (1期 2期 押金)")
    private String accountTypeName;

    @ApiModelProperty("账单分组")
    private Integer groupId;

    /** 账单类型  (租约 加收费用 记账) */
    @ApiModelProperty("账单类型  (租约 加收费用 记账)")
    @Excel(name = "账单类型  (租约 加收费用 记账)")
    private Integer accountType;

    /** 周期类型 */
    @ApiModelProperty("周期类型")
    @Excel(name = "周期类型")
    private Integer cycleType;

    /** 账单开始日期 */
    @ApiModelProperty("账单开始日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "账单开始日期", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date billBeginTime;

    /** 账单结束日期 */
    @ApiModelProperty("账单结束日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "账单结束日期", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date billEndTime;

    /** 应收账款 */
    @ApiModelProperty("应收账款")
    @Excel(name = "应收账款")
    private BigDecimal receivables;

    /** 剩余账款 */
    @ApiModelProperty("剩余账款")
    @Excel(name = "剩余账款")
    private BigDecimal leftPayment;

    /** 已收账款 */
    @ApiModelProperty("已收账款")
    @Excel(name = "已收账款")
    private BigDecimal receivedPayment;

    /** 支付类型 */
    @ApiModelProperty("支付类型")
    @Excel(name = "支付类型")
    private Integer paymentType;

    /** 支付日期 */
    @ApiModelProperty("支付日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "支付日期", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date deadLine;

    /** 账单状态 0-待收,1-已完成 */
    @ApiModelProperty("账单状态 0-待收,1-已完成")
    @Excel(name = "账单状态 0-待收,1-已完成")
    private Integer billStatus;

    /** 支付状态 */
    @ApiModelProperty("支付状态")
    @Excel(name = "支付状态")
    private Integer paymentPayType;

    /** 支付时间 */
    @ApiModelProperty("支付时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "支付时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date paymentTime;

    /** 支付金额 */
    @ApiModelProperty("支付金额")
    @Excel(name = "支付金额")
    private BigDecimal paymentMoney;

    /** 支付状态 0-未支付,1待审批,3-被驳回,4-已完成 */
    @ApiModelProperty("支付状态 0-未支付,1待审批,3-被驳回,4-已完成")
    @Excel(name = "支付状态 0-未支付,1待审批,3-被驳回,4-已完成")
    private Integer paymentStatus;


    public OwnAccountInstallment(String id, String accountDetailsId, String delFlag) {
        this.id = id;
        this.accountDetailsId = accountDetailsId;
        this.delFlag = delFlag;
    }

    public OwnAccountInstallment(
             String detailsId
            , String contractId
            , int i
            , BillAccountTypeEnum billAccountTypeEnum
            , String startTime
            , String endTime
            , BigDecimal rent
    ) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            this.accountDetailsId = detailsId;
            this.contractId = contractId;
            this.accountTypeName = ("第" + (i+1) + "期");
            this.groupId = i+1;
            this.accountType = (billAccountTypeEnum.getId());
            this.cycleType = (null);
            this.billBeginTime = (simpleDateFormat.parse(startTime));
            this.billEndTime= (simpleDateFormat.parse(endTime));
            this.receivables= (rent);
            this.leftPayment= (rent);
            this.receivedPayment= (new BigDecimal("0.00"));
            this.paymentType= (null);
            this.deadLine= (null);
            this.billStatus= (0);

            this.paymentPayType= (0);
            this.paymentTime= (null);
            this.paymentMoney= (null);
            //TODO: creator->RazaJin 处理时间->闲了  问题-> 支付状态改成枚举
            this.paymentStatus = (AccountInstallmentPaymentStatusEnum.NON.getId());
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
